package org.tissou.client.Panel_Premier;


import com.google.gwt.user.client.ui.*;
import org.tissou.client.Panel_Premier.operations_tab.TAB_Operation;
import org.tissou.client.Panel_Premier.comptes_tab.TAB_Comptes;
import org.tissou.client.Panel_Premier.caracteristiques_tab.TAB_Caracteristiques;
import org.tissou.client.Panel_Premier.dettes_tab.TAB_Dettes;
import org.tissou.client.Panel_Premier.bilan_tab.TAB_Bilan;
import org.tissou.client.Panel_Premier.import_tab.TAB_Importation;
import org.tissou.client.Panel_Premier.gestion_tab.TAB_Gestion;

import org.tissou.client.Interface.Base_Panel;
import org.tissou.client.Services.InformationsGlobales;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: Claire
 * Date: 28-Feb-2009
 * Time: 19:16:55
 * To change this template use File | Settings | File Templates.
 */
public class Panel_Premier extends Base_Panel {
  final Label datelabel = new Label();
  final Label proprietaire = new Label();
  final Button changmtProprietaire = new Button();
  DockPanel main_NORD = new DockPanel();

  DockPanel bilan = new DockPanel();
  final DockPanel principal = new DockPanel();

  TabPanel main_CENTRE = new TabPanel();
  DockPanel panel_operation = new DockPanel();
  DockPanel panel_compte = new DockPanel();
  DockPanel panel_dette = new DockPanel();
  DockPanel panel_bilan = new DockPanel();
  DockPanel panel_caracteristiques = new DockPanel();
  DockPanel panel_gestion = new DockPanel();
  DockPanel panel_importation = new DockPanel();

  protected void MiseEnPlaceParametresWidgets(){
    Date date = new Date();
    datelabel.setText(date.toString());
    datelabel.setWidth("300px");
    proprietaire.setText(InformationsGlobales.personneLoguee.getNom());
    changmtProprietaire.setText("Changer Proprietaire");
  }

  protected void MiseEnPlaceStyles() {
      // TODO(Clairette): Fixer tous ces acces a des variables privees toutes pourrites, ma chere Clairette.
    principal.addStyleName("main");
    main_NORD.addStyleName("main_NORD");
    main_CENTRE.addStyleName("main_CENTRE");
    proprietaire.addStyleName("proprietaire");
    proprietaire.addStyleName("defaultstyle");
    datelabel.addStyleName("defaultstyle");
}

  protected void MiseEnPlaceParametresPanel(){

    main_NORD.add(datelabel, DockPanel.WEST);
    main_NORD.add(changmtProprietaire, DockPanel.EAST);
    main_NORD.add(proprietaire, DockPanel.EAST);
    main_NORD.setCellHorizontalAlignment(changmtProprietaire, DockPanel.ALIGN_RIGHT);
    main_NORD.setCellHorizontalAlignment(proprietaire, DockPanel.ALIGN_RIGHT);
    main_NORD.setCellWidth(proprietaire, "100%");
    main_CENTRE.setHeight("560px");

    main_CENTRE.add(panel_operation,"Nouvelle Operation");
    main_CENTRE.add(panel_compte,"Mes comptes");
    main_CENTRE.add(panel_dette,"Mes dettes");
    main_CENTRE.add(panel_bilan,"Bilan");
    main_CENTRE.add(panel_caracteristiques,"Mes caracteristiques");
    main_CENTRE.add(panel_gestion,"Gestion");
    main_CENTRE.add(panel_importation, "Importation");
  }

  protected void MiseEnPlacePanels(){
    principal.add(main_NORD,DockPanel.NORTH);
    principal.add(main_CENTRE, DockPanel.NORTH);
    principal.setCellHeight(main_CENTRE, "100%");
  }

  public Panel donneLePanelPrincipal() {
    return principal;
  }

  protected void MiseEnPlaceActions(){
    changmtProprietaire.addClickListener(new ClickListener(){

      public void onClick(Widget sender) {
        RootPanel.get().remove(principal);
        Panel_PrePremier ppp = new Panel_PrePremier();
        ppp.afficherDans(RootPanel.get());
      }
    });

    main_CENTRE.addTabListener(new TabListener(){

      public boolean onBeforeTabSelected(SourcesTabEvents sender, int tabIndex) {
        return true;  
      }

      public void onTabSelected(SourcesTabEvents sender, int tabIndex) {
        Widget currentWidget = ((TabPanel)sender).getDeckPanel().getWidget(tabIndex);
        DockPanel panel_selectionne;
        Base_Panel panel = null;
        if(currentWidget instanceof DockPanel) {
          
          panel_selectionne = (DockPanel) currentWidget;
          panel_selectionne.clear();

          switch (tabIndex){
            case 0:
              panel = new TAB_Operation();
              break;
            case 1:
              panel = new TAB_Comptes();
              break;
            case 2:
              panel = new TAB_Dettes();
              break;
            case 3:
              panel = new TAB_Bilan();
              break;
            case 4:
              panel = new TAB_Caracteristiques();
              break;
            case 5:
              panel = new TAB_Gestion();
              break;
            case 6:
              panel = new TAB_Importation();

              break;
            default:
              break;
          }
          panel_selectionne.add(panel.construireEtRenvoyerPrincipal(), DockPanel.NORTH);
          panel.jeTeCliqueSurLaGueule();
        }
      }
    });

  }
}
